package com.utils.erweima.zxing;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
import com.utils.erweima.qrcode.JavaQRCode;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class QRCodeUtils {

    /**
     * 生成二维码zxing
     * @param content
     * @param path
     */
    public static void createQRCodeZxing(String content, String path){
        int width = 300;
        int height = 300;
        String format = "png";
        Map<EncodeHintType, Object> map = new HashMap<>();
        //文字编码
        map.put(EncodeHintType.CHARACTER_SET, "utf-8");
        try {
            //BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height);
            BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, map);
            MatrixToImageWriter.writeToFile(bitMatrix, format, new File(path));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 生成二维码
     * @param content
     * @param path
     */
    public static void createQRCode(String content, String path){
        JavaQRCode handler = new JavaQRCode();
        handler.encoderQRCode(content, path, "png", 10);
    }

}
